package com.purchase.ml.utils;

import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by kyyang on 2021/3/2 21:38
 */
@Slf4j
public class DateUtils {
    public static final String yyyyMMddHHmmssStr = "yyyy-MM-dd HH:mm:ss";
    public static final String yyyy_MM_ddStr = "yyyy-MM-dd";
    public static final String yyyyMMddStr = "yyyyMMdd";
    public static final String yyyyMMStr = "yyyyMM";
    public static final String MMStr = "MM";
    public static final String yyyyStr = "yyyy";
    public static final String yyyy_MMStr = "yyyy_MM";
    public static final String yyyy_wwStr = "yyyy_ww";
    public static final String yyyy_MMStr2 = "yyyy-MM";


    public static final ThreadLocal<SimpleDateFormat> nomalFormat = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyyMMddHHmmssStr);
        }
    };

    public static final ThreadLocal<SimpleDateFormat> dayFormat = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyy_MM_ddStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> dayFormat2 = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyyMMddStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> yyyyMM = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyyMMStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> MM = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(MMStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> yyyy = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyyStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> yyyy_MM = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyy_MMStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> yyyy_ww = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyy_wwStr);
        }
    };
    public static final ThreadLocal<SimpleDateFormat> yyyy_MM2 = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return new SimpleDateFormat(yyyy_MMStr2);
        }
    };

    /**
     * @description: 获取两个时间的差异  yyyy-MM-dd
     * @author kyyang
     * @date 2021/3/30 19:27
     * @version 1.0
     */
    public static final int getDateDiff(String start,String end) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = new Date();
        Date date2 = new Date();
        try {
             date1 = format.parse(start);
             date2 = format.parse(end);
        }catch (Exception e){
            log.error("时间解析异常,start::[{}],end::[{}]",start,end);
        }
        int d = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
        return d;

    }

    public static void main(String[] args) {
        System.out.println(getDateDiff("2021-01-01","2021-0330"));
    }


}
